package biz.datalk.industrialland.common.validated;

import biz.datalk.industrialland.common.validated.validator.ChkIntegerValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Integer 类型校验
 *
 * @author tarofang@163.com
 * @date 2024-01-24
 */
@Documented
@Constraint(validatedBy = ChkIntegerValidator.class)
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ChkInteger {
    /**
     * 是否是必传
     * true - 必传 不能为 null
     * false - 非必传 可以为null, 非 null 值时校验值是否在列表
     */
    boolean required() default true;

    /** 非可选值的提示 */
    String message() default "";

    /** null 值时的提示 */
    String nullMessage() default "";


    /** 可选值 */
    int[] optVal() default {};

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        ChkInteger[] value();
    }
}
